package com.etc.service.impl;/*
 * 文件名：com.etc.service.impl.UserPersonalServiceImpl
 * 描述：
 * 作者：黄志鹏
 * 时间：2019/5/28 9:16
 */

import com.etc.dao.OrdersDao;
import com.etc.dao.UserDao;

import com.etc.entity.Orders;
import com.etc.entity.User;
import com.etc.service.UserPersonalService;
import com.etc.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserPersonalServiceImpl implements UserPersonalService {

    @Autowired
    private UserDao userDao ;

    @Autowired
    private OrdersDao ordersDao;
    /**
     * 根据用户查询用户信息
     * @param userid 要查询的用户id
     * @return 查询到的用户信息
     */
    @Override
    public User getUserByUserid(Integer userid) {
        return userDao.selectByPrimaryKey(userid);
    }

    @Override
    public boolean updateUserDataByUserid(User user) {
        user.setUserpassword(MD5Util.getEncodeByMd5(user.getUserpassword()));
        if (user.getUserpassword().equals("")||user.getUserpassword()==null){
            return userDao.updateUserDataByUserid1(user);
        }else {
            return userDao.updateUserDataByUserid2(user);
        }

    }

    /**
     *
     * @param userid
     * @return
     */
    @Override
    public List<Orders> listOrdersByUserid(Integer userid) {
        return ordersDao.listOrdersByUserid(userid);
    }

    /**
     * 确认收货的方法
     * @param orderid 要确认的id
     * @return 是否操作成功
     */
    @Override
    public boolean confirmOrders(Integer orderid) {
        return ordersDao.UpdateOrdersByOrdersid(orderid);
    }

    /**
     * 删除订单的方法
     * @param orderid 要删除的订单id
     * @return
     */
    @Override
    public boolean deleteOrder(Integer orderid) {
        return ordersDao.updateOrderByOrderid(orderid);
    }

    /**
     * 根据订单编号查询订单信息
     * @param orderid 订单编号
     * @return 查询到的结果
     */
    @Override
    public Orders getOrdersByOrderid(Integer orderid) {
        return ordersDao.getOrdersByOrderid(orderid);
    }
}
